package com.czwj.action;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import com.czwj.annotation.SystemControllerLog;
import com.czwj.entities.DataGridData;
import com.czwj.entities.OperateResult;
import com.czwj.entities.PageBean;
import com.czwj.entities.Permission;
import com.czwj.entities.Role;
import com.czwj.entities.SummaryUser;
import com.czwj.entities.UserInfo;
import com.czwj.service.PermissionService;
import com.czwj.service.RoleService;
import com.czwj.service.SummaryUserService;
import com.czwj.service.UserInfoService;
import com.czwj.util.TextUtil;

/**
* @ClassName: SummaryAction
* @Description: TODO
* @author H
* @date 2019年12月27日
*
*/
@Controller
public class SummaryAction{
	@Resource
	UserInfoService userInfoService;
	@Resource
	SummaryUserService summaryUserService;
	
	@RequestMapping(value = "summaryroles",method = RequestMethod.GET)
	@ResponseBody
	public DataGridData<Role> getRoles(@RequestParam(value = "page",required = false) String page,
			@RequestParam(value = "rows",required = false) String rows){
		DataGridData<Role> result = new DataGridData<>();
		Map<String,Object> params = new HashMap<>();
		PageBean pageBean = null;
		if(TextUtil.isNotEmpty(page) && TextUtil.isNotEmpty(rows))
			pageBean = new PageBean(Integer.parseInt(page),Integer.parseInt(rows));
		if(pageBean != null){
			params.put("start",pageBean.getStart());
			params.put("size",pageBean.getPageSize());
		}
		Subject currentUser = SecurityUtils.getSubject();
		int companyid = ((UserInfo)currentUser.getSession().getAttribute("userInfo")).getCompanyid();
		params.put("companyid",companyid);
		List<Role> list = summaryUserService.selectByCompany(params);
		int total = summaryUserService.countByCompany(params);
		result.setRows(list);
		result.setTotal(total);
		return result;
	}
	
	@RequestMapping(value = "/summarys",method = RequestMethod.POST)
	@ResponseBody
	public List<SummaryUser> summarys(){
		List<SummaryUser> list = summaryUserService.selectAll();
		return list;
	}
	
}
